package com.galaxy.user.api;

import com.galaxy.common.core.domain.R;
import com.galaxy.common.web.core.BaseController;
import com.galaxy.user.domain.UserBase;
import com.galaxy.user.domain.convert.UserBaseConvert;
import com.galaxy.user.domain.vo.UserBaseVo;
import com.galaxy.user.service.UserBaseService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/userInfo")
public class UserInfoApiController extends BaseController {

    private final UserBaseService userBaseService;

    private final UserBaseConvert userBaseConvert;
    @PostMapping("/code")
    public R<UserBaseVo> wxLogin(@RequestBody UserBase userBase){
        UserBaseVo userInfo = userBaseService.wxLogin(userBase);
        return R.ok(userInfo);
    }

    @PutMapping("/update")
    public R<UserBase> updateUserInfo(@RequestBody UserBase userBase) {
        UserBase updatedUser = userBaseService.wxUpdate(userBase);
        return R.ok(updatedUser);
    }

    @PutMapping("/updateAvatar")
    public R<UserBase> updateAvatar(@RequestBody UserBase userBase) {
        UserBase updatedUser = userBaseService.updateAvatar(userBase.getId(),userBase.getAvatar());
        return R.ok(updatedUser);
    }
    @GetMapping("/{id}")
    public R<UserBaseVo> getInfo(@PathVariable Long id) {
        UserBase userBase = userBaseService.queryById(id);
        return R.ok(userBaseConvert.convertVo(userBase));
    }

    @GetMapping("/getOpen/{id}")
    public R<String> getOpenid(@PathVariable Long id) {
        return R.ok("数据获取成功",userBaseService.getOpenidByUserId(id));
    }

}
